package com.zy.explore.module.message.interfaces.facade.example;

import com.zy.explore.module.message.application.event.publish.MqSender;
import com.zy.explore.module.message.interfaces.vo.ExampleVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * description Redis示例Facade
 *
 * @author ZY
 * @date 2021年10月10日 23:09
 */
@Api(tags = {"RocketMQ示例Facade"})
@RestController
@RequestMapping("/mq")
public class RocketMqExampleFacade {

    @Resource
    private MqSender sender;

    @ApiOperation("①发送简单消息测试")
    @GetMapping("/sendMsg1")
    public Boolean sendMsg1(@RequestParam String msg) {
        return sender.send(msg);
    }

    @ApiOperation("②发送Tag消息测试")
    @GetMapping("/sendMsg2")
    public Boolean sendMsg2(@RequestParam String msg, @RequestParam String tag) {
        return sender.sendWithTags(msg, tag);
    }

    @ApiOperation("③发送对象消息测试")
    @GetMapping("/sendMsg3")
    public ExampleVO sendMsg3(@RequestParam String name, @RequestParam String address) {
        ExampleVO entity = ExampleVO.builder().name(name).address(address).build();
        return sender.sendObject(entity, "tagObj");
    }

    @ApiOperation("④发送事务消息测试")
    @GetMapping("/sendMsg4")
    public ExampleVO sendMsg4(@RequestParam String name, @RequestParam String address) {
        ExampleVO entity = ExampleVO.builder().name(name).address(address).build();
        return sender.sendTransactionalMsg(entity, 1);
    }

    @ApiOperation("⑤发送手动拉取消费的消息")
    @GetMapping("/sendMsg5")
    public boolean sendMsg5(@RequestParam String msg) {
        return sender.sendPullMessage(msg);
    }


}
